(function(global, document, _fns, $, console) {
  'use strict';

  /*
  
      @name 自动嵌套命名空间
  
      @desc
  
      @author
  
      @access protected
  
      @function _extend
  
      @param {Object} ns 顶级命名空间
  
      @param {string} [nsString = tlns.ns1.ns2.ns3] 基于顶级命名空间要嵌套的命名空间
  
      @returns {Object} 返回嵌套好的对象。
  
      @example
          // " tlns.sample = $.noop; " === " tlns.ns1.ns2.ns3.sample = $.noop; "
          var tlns = _extend(tlns, "tlns.ns1.ns2.ns3");
  
      @todo 将这个函数放入公共函数库中。
   */
  var _extend, exc;
  _extend = function(ns, nsString) {
    var i, parent, parts, pl;
    parts = nsString.split(".");
    parent = ns;
    pl = parts.length;
    i = 0;
    while (i < pl) {
      if (typeof parent[parts[i]] === "undefined") {
        parent[parts[i]] = {};
      }
      parent = parent[parts[i]];
      i++;
    }
    return parent;
  };
  exc = _extend(_fns, "_fns.excute");

  /*
      @desc
  
      @author
  
      @access protected
  
      @function exc._fast_click
   */
  exc.sidebar = function() {
    global.lsBar();
  };

  /*
   * 删除收藏
   */
  exc.removeCollect = function() {
	    var btnRemoveCollect, fnRemoveCollect, curCollectId;
	    btnRemoveCollect = $('.btn-remove-collection');
	    fnRemoveCollect = function(e) {
	      var closestTr, that;
	      e.stopPropagation();
	      e.preventDefault();
	      that = $(this);
	      closestTr = that.closest('tr');
	      curCollectId = closestTr.data('colid');
	      console.log(curCollectId);
	      var ajaxDelCol = $.ajax('/member/delCollect.htm?channelCode=1', {
	    	  data: {
	    		  'spuId' : curCollectId
	    	  }
	      });
	      ajaxDelCol.done(function(data, textStatus, jqXHR) {
	    	  closestTr.remove();
	    	 /* ECar.easyDialog.open({
					container : {
						header : '提示',
						content : '<div style="text-align:center">删除成功</div>'
					}
				});*/
	    	  location.reload(true);
	      });
	      ajaxDelCol.fail(function(jqXHR, textStatus, errorThrown) {
	    	  ECar.easyDialog.open({
					container : {
						header : '提示',
						content : '<div style="text-align:center">删除失败</div>'
					}
				});
	      });
	    };
	    btnRemoveCollect.on('click', fnRemoveCollect);
	  };
  
  /*
      @name 初始化
  
      @desc 所有在 " _fns.excute " 命名空间下定义的函数将被自动运行。
  
      @author
  
      @access protected
  
      @function _fns.init
  
      @param {Object} opts 存放定义好的可任意修改（配置）的行为选项。
   */
  _fns.init = function(opts) {
    var _it;
    for (_it in exc) {
      if (typeof exc[_it] === "function") {
        exc[_it]();
      }
    }
  };
  $(_fns.init);
})(window, document, {}, jQuery, (typeof console !== 'undefined' ? console : void 0));
